class Event < ActiveRecord::Base
  acts_as_taggable
  
  belongs_to :user
  belongs_to :place
  
  before_create :set_nicetitle
  
  has_many  :contacts
  has_many  :comments, :order => "created_at DESC"
  has_many  :event_images
  
  def invitations
    self.contacts.find(:all, :conditions => {:confirm => nil})
  end
  
  def confirmations
    self.contacts.find(:all, :conditions => {:confirm => true})    
  end

  def denegations
    self.contacts.find(:all, :conditions => {:confirm => false})    
  end
  
  def get_title
    self.title.blank? ? 'evento sin titulo' : self.title
  end
  
  
  
  def to_param
    "#{id}-#{title.sanitize}"
  end

  private

  def set_nicetitle
    self.nicetitle = self.title.sanitize
  end
end

